package com.oscar.web.service;

import com.oscar.web.dao.UserRepository;
import com.oscar.web.domain.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UsersService {
    @Autowired
    private UserRepository userRepository ;

    public Users findByUsername(String username){
        return  userRepository.findByUsername(username,Users.class) ;
    }

    public String saveUser(Users u) {//用户注册
        String msg ="注册成功，恭喜你成为我们尊贵的VIP用户！";
        if (userRepository.existsUsersByUsername(u.getUsername())){
            msg="用户名已被使用，请换个名字试试。";
        }else{
            userRepository.save(u);
        }
        return msg;
    }
}
